﻿using Sys.Core.Gen;
using Sys.Core.Sys;
using Sys.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class NewList : System.Web.UI.Page
{
    public SysDictionary model { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string tag = Request.QueryString["tag"];

            if (!string.IsNullOrEmpty(tag))
            {
                model = DictionaryBll.I.Entities.FirstOrDefault(m => m.Tag.Equals(tag));

                if (model != null)
                {
                    ListInit(tag);

                    Home mas = Master as Home;

                    mas.SetHead(model.Name, model.Name, model.Name);
                }
                else { model = new SysDictionary(); }
            }
            else { model = new SysDictionary(); }
        }
    }

    public void ListInit(string tag)
    {
        var entities = NewBll.I.NewsByTag(tag);

        int recordcount = entities.Count();
        int page = Convert.ToInt32(Request.QueryString["page"]);
        int rows = 20;
        if (page == 0) { page = 1; }

        rep_List.DataSource = NewBll.I.EntitiesPage(entities, rows, page).ToList();
        rep_List.DataBind();

        Pager.UpdatePage(recordcount, rows, page, Request.Url.LocalPath, "&tag=" + tag);
    }
}